#include <iostream>
#include <vector>
#include <string>

using namespace std;

string simplifyPath(string path) {
    vector<string> st; int i = 0, pre = 0;
    while(i < path.size()){
        while(i < path.size() && path[i] == '/') i++;
        pre = i;
        while(i < path.size() && path[i] != '/') i++;
        string t = path.substr(pre, i - pre);
        if(t == "." || t == ""){
            continue;
        }else if(t == ".."){
            if(!st.empty()) st.pop_back();
        }else{
            st.push_back(t);
        }
    }
    path.clear();
    for(auto it = st.begin(); it != st.end(); it++){
        path += "/" + *it;
    }
    return path.empty() ? "/" : path;
}

int main(){
    string path = "/home//foo/";
    cout << simplifyPath(path) << endl;
    return 0;
}
